﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using App.Model;

namespace App.Realization
{
    public class Mappeing
    {
        public static MyKaoHeBiao ToMyKaoHeBiao(dynamic DynamicObject)
        {
            MyKaoHeBiao tt = new MyKaoHeBiao();
            tt.sssj = DynamicObject.sssj;
            tt.khbzt = DynamicObject.state;
            tt.cjsj = DynamicObject.cjsj;
            tt.mkhbid = DynamicObject.pmid;
            tt.mkhbmc = DynamicObject.tableName;
            tt.mbid = DynamicObject.mobanid;
            tt.MyKaoHeZongJie = new zongjieone();
            if (DynamicObject.PersonalWorkSummary != null)
            {
                //tt.MyKaoHeZongJie. = DynamicObject.PersonalWorkSummary.cjsj;
                //tt.MyKaoHeZongJie. = DynamicObject.PersonalWorkSummary.wsid;
                tt.MyKaoHeZongJie.zjmc = DynamicObject.PersonalWorkSummary.zjmc;
                tt.MyKaoHeZongJie.Zongjietwos = new List<zongjietwo>();
                if (DynamicObject.PersonalWorkSummary.WorkSummaryItems.Type != Newtonsoft.Json.Linq.JTokenType.Null)
                {
                    foreach (var item in DynamicObject.PersonalWorkSummary.WorkSummaryItems)
                    {
                        zongjietwo wi = new zongjietwo();
                        //wi. = item.cjsj;
                        wi.zjtowid = item.wsiid;
                        wi.zongjielx = item.zjlx;
                        wi.zongjienr = item.zjnr;
                        tt.MyKaoHeZongJie.Zongjietwos.Add(wi);
                    }
                }

            }
            tt.StateLog = new List<PersonalMainStateLog>();
            foreach (var item in DynamicObject.StateLog)
            {
                PersonalMainStateLog pmsl = new PersonalMainStateLog();
                pmsl.cjrid = item.cjrid;
                pmsl.cjsj = item.cjsj;
                pmsl.id = item.id;
                pmsl.isread = item.isread;
                pmsl.PersonalState = item.PersonalState;
                pmsl.msg = item.msg;
                tt.StateLog.Add(pmsl);
            }
            tt.MyKaoHeBiaoFujiaxiangs = new List<MyKaoHeBiaoFuJiaBiao>();
            foreach (var item in DynamicObject.AdditionalItems)
            {
                MyKaoHeBiaoFuJiaBiao ai = new MyKaoHeBiaoFuJiaBiao();
                ai.cjrid = item.cjrid;
                ai.cjsj = item.cjsj;
                ai.fjxid = item.fjxid;
                ai.xmfz = item.xmfz;
                ai.xmid = item.xmid;
                ai.xmmc = item.xmmc;
                tt.MyKaoHeBiaoFujiaxiangs.Add(ai);
            }
            tt.MyKaoHeBiaoOnes = new List<MyKaoHeBiaoOne>();
            foreach (var item in DynamicObject.PersonalPath)
            {
                MyKaoHeBiaoOne pp = new MyKaoHeBiaoOne();
                pp.ControlID = item.ControlID;
                pp.fz = item.fenzhi;
                pp.isedit = item.isEdit;
                pp.isinclude = item.isinclude;
                pp.mbnr = item.ljmc;
                pp.mbid = item.mpid;
                pp.paths = item.paths;
                pp.oneid = item.ppid;
                pp.sx = item.shunxu;
                pp.sonmobanfenzhi = item.sonmobanfenzhi;
                pp.sonmobanid = item.sonmobanid;
                pp.MyKaoHeBiaoTwos = new List<MyKaoHeBiaotwo>();
                foreach (var item2 in item.PersonalContents)
                {
                    MyKaoHeBiaotwo pc = new MyKaoHeBiaotwo();
                    pc.fz = item2.fenzhi;
                    pc.sx = item.shunxu;
                    pc.gzcdrid = item2.gzcdrid;
                    pc.gzcdr = item2.gzcdr;
                    pc.cjrid = item2.cjrid;
                    pc.cjsj = item2.cjsj;
                    pc.IsEdit = item2.isedit;
                    pc.Iswc = item2.iswc;
                    pc.gzjhwcsj = item2.jssj;
                    pc.gzjhkssj = item2.kssj;
                    pc.lyid = item2.laiyuan;
                    pc.ljcs = item2.ljcs;
                    pc.mbnr = item2.nr;
                    pc.twoid = item2.pcid;
                    pc.gzjhwcqk = item2.wcqk;
                    pc.zhou = item2.zhou;
                    pc.zp = item2.zpf;
                    pc.MyKaoHeBiaotwoFuJianses = new List<MyKaoHeBiaotwo_FuJians>();
                    foreach (var item3 in item2.PersonalEnclosures)
                    {
                        MyKaoHeBiaotwo_FuJians pe = new MyKaoHeBiaotwo_FuJians();
                        //pe. = item3.content;
                        pe.fileHash = item3.fileHash;
                        pe.fileguid = item3.fileguid;
                        pe.path = item3.path;
                        pe.fjid = item3.fjid;
                        pe.fjmc = item3.fjmc;
                        pc.MyKaoHeBiaotwoFuJianses.Add(pe);
                    }
                    pc.MyKaoHeBiaoTwoPingFens = new List<MyKaoHeBiaoPingFen>();
                    foreach (var item3 in item2.PersonalEvaluates)
                    {
                        MyKaoHeBiaoPingFen pe = new MyKaoHeBiaoPingFen();
                        pe.cjsj = item3.cjsj;
                        pe.fz = item3.fz;
                        pe.pjrid = item3.pjrid;
                        pe.iseffective = item3.iseffective;
                        pe.pfid = item3.pjid;
                        pc.MyKaoHeBiaoTwoPingFens.Add(pe);
                    }

                    if (item2.PersonalOrigin != null && item2.PersonalOrigin.pmid > 0)
                    {
                        pc.PersonalOrigin = new PersonalOrigin();
                        pc.PersonalOrigin.lyxingming = item2.PersonalOrigin.lyxingming;
                        pc.PersonalOrigin.pcid = item2.PersonalOrigin.pcid;
                        pc.PersonalOrigin.pmid = item2.PersonalOrigin.pmid;
                    }
                    pc.xiangguangongzuoji = new List<xiangguangongzuo>();
                    foreach (var item3 in item2.RelevantWorks)
                    {
                        xiangguangongzuo rw = new xiangguangongzuo();
                        rw.xggzid = item3.pcid;
                        rw.xggzid = item3.xggzid;
                        pc.xiangguangongzuoji.Add(rw);
                    }
                    pc.PersonalAnswers = new List<PersonalAnswer>();
                    foreach (var item3 in item2.PersonalAnswers)
                    {
                        PersonalAnswer pa = new PersonalAnswer();
                        pa.fenzhi = item3.fenzhi;
                        pa.html = item3.html;
                        pa.paid = item3.paid;
                        pa.shunxu = item3.shunxu;
                        pa.tips = item3.tips;
                        pc.PersonalAnswers.Add(pa);
                    }
                    pp.MyKaoHeBiaoTwos.Add(pc);
                }
                tt.MyKaoHeBiaoOnes.Add(pp);
            }

            return tt;
        }
    }
}
